<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />

<meta name="viewport" content="width=device-width, initial-scale=1">

<meta name="author" content="WMB Edmands" />

<meta name="date" content="2017-06-12" />

<title>simExTargId (simultaneous experiment - MS/MS target identification)</title>



<style type="text/css">code{white-space: pre;}</style>
<style type="text/css">
div.sourceCode { overflow-x: auto; }
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
  margin: 0; padding: 0; vertical-align: baseline; border: none; }
table.sourceCode { width: 100%; line-height: 100%; }
td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
td.sourceCode { padding-left: 5px; }
code > span.kw { color: #007020; font-weight: bold; } /* Keyword */
code > span.dt { color: #902000; } /* DataType */
code > span.dv { color: #40a070; } /* DecVal */
code > span.bn { color: #40a070; } /* BaseN */
code > span.fl { color: #40a070; } /* Float */
code > span.ch { color: #4070a0; } /* Char */
code > span.st { color: #4070a0; } /* String */
code > span.co { color: #60a0b0; font-style: italic; } /* Comment */
code > span.ot { color: #007020; } /* Other */
code > span.al { color: #ff0000; font-weight: bold; } /* Alert */
code > span.fu { color: #06287e; } /* Function */
code > span.er { color: #ff0000; font-weight: bold; } /* Error */
code > span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
code > span.cn { color: #880000; } /* Constant */
code > span.sc { color: #4070a0; } /* SpecialChar */
code > span.vs { color: #4070a0; } /* VerbatimString */
code > span.ss { color: #bb6688; } /* SpecialString */
code > span.im { } /* Import */
code > span.va { color: #19177c; } /* Variable */
code > span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code > span.op { color: #666666; } /* Operator */
code > span.bu { } /* BuiltIn */
code > span.ex { } /* Extension */
code > span.pp { color: #bc7a00; } /* Preprocessor */
code > span.at { color: #7d9029; } /* Attribute */
code > span.do { color: #ba2121; font-style: italic; } /* Documentation */
code > span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code > span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
</style>



<link href="data:text/css;charset=utf-8,body%20%7B%0Abackground%2Dcolor%3A%20%23fff%3B%0Amargin%3A%201em%20auto%3B%0Amax%2Dwidth%3A%20700px%3B%0Aoverflow%3A%20visible%3B%0Apadding%2Dleft%3A%202em%3B%0Apadding%2Dright%3A%202em%3B%0Afont%2Dfamily%3A%20%22Open%20Sans%22%2C%20%22Helvetica%20Neue%22%2C%20Helvetica%2C%20Arial%2C%20sans%2Dserif%3B%0Afont%2Dsize%3A%2014px%3B%0Aline%2Dheight%3A%201%2E35%3B%0A%7D%0A%23header%20%7B%0Atext%2Dalign%3A%20center%3B%0A%7D%0A%23TOC%20%7B%0Aclear%3A%20both%3B%0Amargin%3A%200%200%2010px%2010px%3B%0Apadding%3A%204px%3B%0Awidth%3A%20400px%3B%0Aborder%3A%201px%20solid%20%23CCCCCC%3B%0Aborder%2Dradius%3A%205px%3B%0Abackground%2Dcolor%3A%20%23f6f6f6%3B%0Afont%2Dsize%3A%2013px%3B%0Aline%2Dheight%3A%201%2E3%3B%0A%7D%0A%23TOC%20%2Etoctitle%20%7B%0Afont%2Dweight%3A%20bold%3B%0Afont%2Dsize%3A%2015px%3B%0Amargin%2Dleft%3A%205px%3B%0A%7D%0A%23TOC%20ul%20%7B%0Apadding%2Dleft%3A%2040px%3B%0Amargin%2Dleft%3A%20%2D1%2E5em%3B%0Amargin%2Dtop%3A%205px%3B%0Amargin%2Dbottom%3A%205px%3B%0A%7D%0A%23TOC%20ul%20ul%20%7B%0Amargin%2Dleft%3A%20%2D2em%3B%0A%7D%0A%23TOC%20li%20%7B%0Aline%2Dheight%3A%2016px%3B%0A%7D%0Atable%20%7B%0Amargin%3A%201em%20auto%3B%0Aborder%2Dwidth%3A%201px%3B%0Aborder%2Dcolor%3A%20%23DDDDDD%3B%0Aborder%2Dstyle%3A%20outset%3B%0Aborder%2Dcollapse%3A%20collapse%3B%0A%7D%0Atable%20th%20%7B%0Aborder%2Dwidth%3A%202px%3B%0Apadding%3A%205px%3B%0Aborder%2Dstyle%3A%20inset%3B%0A%7D%0Atable%20td%20%7B%0Aborder%2Dwidth%3A%201px%3B%0Aborder%2Dstyle%3A%20inset%3B%0Aline%2Dheight%3A%2018px%3B%0Apadding%3A%205px%205px%3B%0A%7D%0Atable%2C%20table%20th%2C%20table%20td%20%7B%0Aborder%2Dleft%2Dstyle%3A%20none%3B%0Aborder%2Dright%2Dstyle%3A%20none%3B%0A%7D%0Atable%20thead%2C%20table%20tr%2Eeven%20%7B%0Abackground%2Dcolor%3A%20%23f7f7f7%3B%0A%7D%0Ap%20%7B%0Amargin%3A%200%2E5em%200%3B%0A%7D%0Ablockquote%20%7B%0Abackground%2Dcolor%3A%20%23f6f6f6%3B%0Apadding%3A%200%2E25em%200%2E75em%3B%0A%7D%0Ahr%20%7B%0Aborder%2Dstyle%3A%20solid%3B%0Aborder%3A%20none%3B%0Aborder%2Dtop%3A%201px%20solid%20%23777%3B%0Amargin%3A%2028px%200%3B%0A%7D%0Adl%20%7B%0Amargin%2Dleft%3A%200%3B%0A%7D%0Adl%20dd%20%7B%0Amargin%2Dbottom%3A%2013px%3B%0Amargin%2Dleft%3A%2013px%3B%0A%7D%0Adl%20dt%20%7B%0Afont%2Dweight%3A%20bold%3B%0A%7D%0Aul%20%7B%0Amargin%2Dtop%3A%200%3B%0A%7D%0Aul%20li%20%7B%0Alist%2Dstyle%3A%20circle%20outside%3B%0A%7D%0Aul%20ul%20%7B%0Amargin%2Dbottom%3A%200%3B%0A%7D%0Apre%2C%20code%20%7B%0Abackground%2Dcolor%3A%20%23f7f7f7%3B%0Aborder%2Dradius%3A%203px%3B%0Acolor%3A%20%23333%3B%0Awhite%2Dspace%3A%20pre%2Dwrap%3B%20%0A%7D%0Apre%20%7B%0Aborder%2Dradius%3A%203px%3B%0Amargin%3A%205px%200px%2010px%200px%3B%0Apadding%3A%2010px%3B%0A%7D%0Apre%3Anot%28%5Bclass%5D%29%20%7B%0Abackground%2Dcolor%3A%20%23f7f7f7%3B%0A%7D%0Acode%20%7B%0Afont%2Dfamily%3A%20Consolas%2C%20Monaco%2C%20%27Courier%20New%27%2C%20monospace%3B%0Afont%2Dsize%3A%2085%25%3B%0A%7D%0Ap%20%3E%20code%2C%20li%20%3E%20code%20%7B%0Apadding%3A%202px%200px%3B%0A%7D%0Adiv%2Efigure%20%7B%0Atext%2Dalign%3A%20center%3B%0A%7D%0Aimg%20%7B%0Abackground%2Dcolor%3A%20%23FFFFFF%3B%0Apadding%3A%202px%3B%0Aborder%3A%201px%20solid%20%23DDDDDD%3B%0Aborder%2Dradius%3A%203px%3B%0Aborder%3A%201px%20solid%20%23CCCCCC%3B%0Amargin%3A%200%205px%3B%0A%7D%0Ah1%20%7B%0Amargin%2Dtop%3A%200%3B%0Afont%2Dsize%3A%2035px%3B%0Aline%2Dheight%3A%2040px%3B%0A%7D%0Ah2%20%7B%0Aborder%2Dbottom%3A%204px%20solid%20%23f7f7f7%3B%0Apadding%2Dtop%3A%2010px%3B%0Apadding%2Dbottom%3A%202px%3B%0Afont%2Dsize%3A%20145%25%3B%0A%7D%0Ah3%20%7B%0Aborder%2Dbottom%3A%202px%20solid%20%23f7f7f7%3B%0Apadding%2Dtop%3A%2010px%3B%0Afont%2Dsize%3A%20120%25%3B%0A%7D%0Ah4%20%7B%0Aborder%2Dbottom%3A%201px%20solid%20%23f7f7f7%3B%0Amargin%2Dleft%3A%208px%3B%0Afont%2Dsize%3A%20105%25%3B%0A%7D%0Ah5%2C%20h6%20%7B%0Aborder%2Dbottom%3A%201px%20solid%20%23ccc%3B%0Afont%2Dsize%3A%20105%25%3B%0A%7D%0Aa%20%7B%0Acolor%3A%20%230033dd%3B%0Atext%2Ddecoration%3A%20none%3B%0A%7D%0Aa%3Ahover%20%7B%0Acolor%3A%20%236666ff%3B%20%7D%0Aa%3Avisited%20%7B%0Acolor%3A%20%23800080%3B%20%7D%0Aa%3Avisited%3Ahover%20%7B%0Acolor%3A%20%23BB00BB%3B%20%7D%0Aa%5Bhref%5E%3D%22http%3A%22%5D%20%7B%0Atext%2Ddecoration%3A%20underline%3B%20%7D%0Aa%5Bhref%5E%3D%22https%3A%22%5D%20%7B%0Atext%2Ddecoration%3A%20underline%3B%20%7D%0A%0Acode%20%3E%20span%2Ekw%20%7B%20color%3A%20%23555%3B%20font%2Dweight%3A%20bold%3B%20%7D%20%0Acode%20%3E%20span%2Edt%20%7B%20color%3A%20%23902000%3B%20%7D%20%0Acode%20%3E%20span%2Edv%20%7B%20color%3A%20%2340a070%3B%20%7D%20%0Acode%20%3E%20span%2Ebn%20%7B%20color%3A%20%23d14%3B%20%7D%20%0Acode%20%3E%20span%2Efl%20%7B%20color%3A%20%23d14%3B%20%7D%20%0Acode%20%3E%20span%2Ech%20%7B%20color%3A%20%23d14%3B%20%7D%20%0Acode%20%3E%20span%2Est%20%7B%20color%3A%20%23d14%3B%20%7D%20%0Acode%20%3E%20span%2Eco%20%7B%20color%3A%20%23888888%3B%20font%2Dstyle%3A%20italic%3B%20%7D%20%0Acode%20%3E%20span%2Eot%20%7B%20color%3A%20%23007020%3B%20%7D%20%0Acode%20%3E%20span%2Eal%20%7B%20color%3A%20%23ff0000%3B%20font%2Dweight%3A%20bold%3B%20%7D%20%0Acode%20%3E%20span%2Efu%20%7B%20color%3A%20%23900%3B%20font%2Dweight%3A%20bold%3B%20%7D%20%20code%20%3E%20span%2Eer%20%7B%20color%3A%20%23a61717%3B%20background%2Dcolor%3A%20%23e3d2d2%3B%20%7D%20%0A" rel="stylesheet" type="text/css" />

</head>

<body>




<h1 class="title toc-ignore">simExTargId (simultaneous experiment - MS/MS target identification)</h1>
<h4 class="author"><em>WMB Edmands</em></h4>
<h4 class="date"><em>June 12, 2017</em></h4>



<p>The following illustrates the simExTargId workflow with example (.RAW) data files of human plasma obtained on a Thermo FT-ICR-MS.</p>
<p>First the warning email notification function (<em>emailNotifier</em>) must be initiated in a seperate R session to monitor the raw data directory on the mass spectrometer workstation.</p>
<p>For the purposes of this vignette the main function (<em>simExTargId</em>) can be illustrated by simulating a real-time data acquisition worklist. First a dummy raw data directory must be created on your computer’s hard drive into which example raw data files can be moved. After moving the raw data files in to the directory their last write time can be adjusted (<em>Sys.setFileTime</em>) to initiate the <strong>simExTargId</strong> autonomous metabolomic data-analysis process. This allows the full functionality of <strong>simExTargId</strong> to be demonstrated with example data rather than when needed for a metabolomic profiling data collection.</p>
<div id="set-the-real-time-email-notifier" class="section level1">
<h1>1. Set the real-time email notifier</h1>
<p>The email notifier must be run in a seperate R session to ensure the raw data directory on the mass spectrometer workstation can be closely monitored and any stoppage/error quickly detected. The <code>emailNotifier</code> function can send warning emails to a character vector of multiple email addresses (e.g. within a laboratory group) if an experimental run has stopped unexpectedly or if there are spray quality issues for example leading to files which are much smaller in size (default: &gt;= 3 median absolute deviations) than the files already collected. If this function formed part of the main <strong>simExTargId</strong> function there might be a delay in informing the user of an unexpected instrument stoppage or spray quality issues for example when file-conversion, peak-picking or another lengthy process is taking place.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># select directory where example directories for raw files can be created and also results</span>
<span class="co"># output saved</span>
<span class="co"># For example the C: directory</span>
<span class="co"># create a dummy raw MS1 profiling data directory </span>
<span class="co"># for example</span>
studyName &lt;-<span class="st"> </span><span class="kw">paste0</span>(<span class="kw">gsub</span>(<span class="st">&quot; &quot;</span>, <span class="st">&quot;&quot;</span>, <span class="kw">format</span>(<span class="kw">Sys.time</span>(), <span class="st">&quot;%Y %m %d&quot;</span>)), <span class="st">&quot;_simExTargId_Example&quot;</span>)
dummyRawDir &lt;-<span class="st"> </span><span class="kw">paste0</span>(<span class="st">&quot;C:/&quot;</span>, studyName)
<span class="co"># create directory</span>
<span class="kw">dir.create</span>(dummyRawDir)
<span class="co"># replace email address with a vector of one or more email addresses of</span>
<span class="co"># people in your laboratory group</span>
<span class="kw">emailNotifier</span>(<span class="dt">rawDir=</span>dummyRawDir, <span class="dt">emailAddress=</span><span class="st">'johndoe@emailprovider.com'</span>, 
              <span class="dt">emailTime=</span><span class="dv">5</span>)</code></pre></div>
</div>
<div id="set-the-main-simextargid-function-running" class="section level1">
<h1>2. Set the main simExTargId function running</h1>
<p>Set the main <code>simExTargId</code> function running in a different R session to the <code>emailNotifier</code> function. This function is essentially a giant wrapper function for a multitude of other R packages and softwares and utilizes a while loop to continually monitor the raw data directory on the mass spectrometer computer until the last data file acquired is beyond a maximum waiting time (see maxTime argument). The function automatically generates a recommended and organized sub-directory structure in to which all output from <code>simExTargId</code> is continually saved.</p>
<p>A co-variates/worklist table supplied at initiation will inform both the xcms sub-directory grouping, the pooled QC-based signal adjustment and CV% filtering, PCA analysis and also the automatic statistical analysis.</p>
<p>As new data files are collected they will be automatically converted to the mzXML open file format (MSConvert, ProteoWizard) and peak-picked (<code>xcmsSet</code>). After a minimum number of files has been collected subsequent stages of retention time alignment (<code>retcor.obiwarp</code>), grouping (<code>xcms::group</code>) and missing peak imputation (<code>xcms::fillPeaks</code>). Following xcms CAMERA identifies pseudospectra, isotopes and ESI adducts/in-source fragments. The resulting peak table is then pre-processed, outliers identified by PCA and finally automatic co-variate based statistical analysis is performed using various functions from the MetMSLine package. A function peakMonitor internal to the simExTargId function is able to monitor signal-drift/attenuation of a database (.csv) of previously identified metabolites supplied at initiation.</p>
<p><strong>N.B.</strong> Make sure that you have the <strong>MSConvert</strong> software in your path if using Windows and that you are able to successfully run the command <code>&gt; MSConvert</code> in your system shell. This is necessary for the automatic mzXML/mzML file conversion process and <strong>simExTargId</strong> will not work successfully without it.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># simExTargId extdata directory</span>
extdataDir &lt;-<span class="st"> </span><span class="kw">system.file</span>(<span class="st">&quot;extdata&quot;</span>, <span class="dt">package=</span><span class="st">&quot;simExTargId&quot;</span>)
<span class="co"># list blank files</span>
blanksRaw &lt;-<span class="st"> </span><span class="kw">list.files</span>(extdataDir, <span class="dt">pattern=</span><span class="st">&quot;blank&quot;</span>, <span class="dt">full.names=</span><span class="ot">TRUE</span>)
<span class="co"># list plasma IPA extract files</span>
samplesRaw &lt;-<span class="st"> </span><span class="kw">list.files</span>(extdataDir, <span class="dt">pattern=</span><span class="st">&quot;sample&quot;</span>, <span class="dt">full.names=</span><span class="ot">TRUE</span>)
<span class="co"># covariates file</span>
coVariates &lt;-<span class="st"> </span><span class="kw">paste</span>(extdataDir, <span class="st">&quot;coVariates.csv&quot;</span>, <span class="dt">sep=</span><span class="st">&quot;/&quot;</span>)
<span class="co"># illustrative metabolite database table</span>
metabDb &lt;-<span class="st"> </span><span class="kw">paste</span>(extdataDir, <span class="st">'exampleMetabDatabase.csv'</span>, <span class="dt">sep=</span><span class="st">'/'</span>)
<span class="co"># identify number of virtual cores for parallel processing using parallel package</span>
nCores &lt;-<span class="st"> </span>parallel::<span class="kw">detectCores</span>()

<span class="co"># as no qc files then use sample files twice to illustrate the</span>
<span class="co"># peakMonitor function</span>

<span class="co"># move the blank files into the temporary directory to start the process</span>
blankRawCopies &lt;-<span class="st"> </span><span class="kw">paste</span>(dummyRawDir, <span class="kw">basename</span>(blanksRaw), <span class="dt">sep=</span><span class="st">&quot;/&quot;</span>)
<span class="kw">file.copy</span>(<span class="dt">from=</span>blanksRaw, <span class="dt">to=</span>blankRawCopies)
<span class="co"># set the file time to simulate the files having been acquired at least 5 mins</span>
<span class="co"># since last modification</span>
setTheTime &lt;-<span class="st"> </span>function(fileCopy, time){
  <span class="kw">Sys.setFileTime</span>(fileCopy, <span class="kw">Sys.time</span>() -<span class="st"> </span>time)
}
<span class="co"># apply to newly copied files</span>
<span class="kw">sapply</span>(blankRawCopies, setTheTime, <span class="dv">240</span>)

<span class="co"># move the plasma samples twice first time rename as QC</span>
<span class="co"># and set the file time less than 5 mins</span>
samplesRawCopies &lt;-<span class="st"> </span><span class="kw">paste</span>(dummyRawDir, <span class="kw">basename</span>(samplesRaw), <span class="dt">sep=</span><span class="st">&quot;/&quot;</span>)
<span class="kw">file.copy</span>(<span class="dt">from=</span>samplesRaw, <span class="dt">to=</span>samplesRawCopies)
qcFiles &lt;-<span class="st"> </span><span class="kw">gsub</span>(<span class="st">'sample'</span>, <span class="st">'qc'</span>, samplesRawCopies)
<span class="kw">file.rename</span>(<span class="dt">from=</span>samplesRawCopies, <span class="dt">to=</span>qcFiles)
<span class="kw">file.copy</span>(<span class="dt">from=</span>samplesRaw, <span class="dt">to=</span>samplesRawCopies)

<span class="co"># apply to newly copied files</span>
<span class="kw">sapply</span>(<span class="kw">c</span>(samplesRawCopies, qcFiles), setTheTime, <span class="dv">300</span>)

<span class="co"># Start simExTargId function</span>
<span class="kw">simExTargId</span>(<span class="dt">rawDir=</span>dummyRawDir, <span class="dt">studyName =</span> studyName, <span class="dt">analysisDir=</span><span class="st">'C:/'</span>,
            <span class="dt">coVar=</span>coVariates, <span class="dt">metab=</span>metabDb, <span class="dt">nCores=</span>nCores, <span class="dt">ionMode=</span><span class="st">'nega'</span>, 
            <span class="dt">minFiles=</span><span class="dv">3</span>)</code></pre></div>
<p>simExTargId will wait until at least five minutes after the raw data file was last modified, to ensure that the file acquisition has fully completed.</p>
<p>After at least 3 samples of each class found in the second column of the co-variates table, retention time alignment, grouping, zero-filling, then pre-processing, PCA analysis, stats analysis and data-deconvolution will occur.</p>
</div>
<div id="peakmonitor-shiny-application" class="section level1">
<h1>3. peakMonitor (shiny application)</h1>
<p>A database table of previously identified metabolites can be monitored in real-time and analytical CV% and signal attenuation affects monitored using the shiny application <code>peakMonitor</code></p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">peakMonitor</span>(<span class="dt">analysisDir=</span><span class="kw">paste0</span>(dummyRawDir, <span class="st">&quot;_analysis/NEG/output/peakMonitor&quot;</span>))</code></pre></div>
</div>
<div id="targetid-shiny-application" class="section level1">
<h1>4. targetId (shiny application)</h1>
<p>During a run the output of the statistical analyses can be viewed using the shiny application <code>targetId</code> a zip file containing containing a .csv file for each statistical test after setting the thresholds can be downloaded and used to guide and plan further MS/MS experiments.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># this command will open the application in your web-browser</span>
<span class="kw">targetId</span>(<span class="dt">analysisDir=</span><span class="kw">paste0</span>(dummyRawDir, <span class="st">&quot;_analysis/NEG/output/04.stats&quot;</span>))</code></pre></div>
</div>



<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
  (function () {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src  = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
    document.getElementsByTagName("head")[0].appendChild(script);
  })();
</script>

</body>
</html>
